package org.lucava.boatskeeper.client.view;

import org.lucava.boatskeeper.client.presenter.EditBoatPresenter;

import com.google.gwt.event.dom.client.HasClickHandlers;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.DecoratorPanel;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HasValue;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class EditBoatView extends Composite implements
		EditBoatPresenter.Display {
	private final TextBox boatName;
	private final TextBox type;
	private final TextBox description;
	private final TextBox latitude;
	private final TextBox longitude;
	private final FlexTable detailsTable;
	private final Button saveButton;
	private final Button cancelButton;

	public EditBoatView() {
		DecoratorPanel contentDetailsDecorator = new DecoratorPanel();
		contentDetailsDecorator.setWidth("18em");
		initWidget(contentDetailsDecorator);

		VerticalPanel contentDetailsPanel = new VerticalPanel();
		contentDetailsPanel.setWidth("100%");

		detailsTable = new FlexTable();
		detailsTable.setCellSpacing(0);
		detailsTable.setWidth("100%");
		detailsTable.addStyleName("contacts-ListContainer");
		detailsTable.getColumnFormatter().addStyleName(1, "add-boat-input");
		boatName = new TextBox();
		type = new TextBox();
		description = new TextBox();
		longitude = new TextBox();
		latitude = new TextBox();
		initDetailsTable();
		contentDetailsPanel.add(detailsTable);

		HorizontalPanel menuPanel = new HorizontalPanel();
		saveButton = new Button("Save");
		cancelButton = new Button("Cancel");
		menuPanel.add(saveButton);
		menuPanel.add(cancelButton);
		contentDetailsPanel.add(menuPanel);
		contentDetailsDecorator.add(contentDetailsPanel);
	}

	private void initDetailsTable() {
		detailsTable.setWidget(0, 0, new Label("BoatName"));
		detailsTable.setWidget(0, 1, boatName);
		detailsTable.setWidget(1, 0, new Label("Type"));
		detailsTable.setWidget(1, 1, type);
		detailsTable.setWidget(2, 0, new Label("Description"));
		detailsTable.setWidget(2, 1, description);
		detailsTable.setWidget(3, 0, new Label("Longitude"));
		detailsTable.setWidget(3, 1, longitude);
		detailsTable.setWidget(4, 0, new Label("Latitude"));
		detailsTable.setWidget(4, 1, latitude);
		boatName.setFocus(true);
	}

	public HasValue<String> getBoatName() {
		return boatName;
	}

	public HasValue<String> getType() {
		return type;
	}

	public HasValue<String> getDescription() {
		return description;
	}

	public HasValue<String> getLongitude() {
		return longitude;
	}

	public HasValue<String> getLatitude() {
		return latitude;
	}

	public HasClickHandlers getSaveButton() {
		return saveButton;
	}

	public HasClickHandlers getCancelButton() {
		return cancelButton;
	}

	public Widget asWidget() {
		return this;
	}

}
